package com.example.mykotlin.model.entity

import com.example.mykotlin.base.valid.Insert
import com.example.mykotlin.base.valid.Update
import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonIgnore
import com.mybatisflex.annotation.Id
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size
import java.time.LocalDateTime

@Schema(name = "User", title = "用户信息表")
open class User(
    @Schema(title = "用户的唯一标识符")
    @Id
    @field:Min(value = 1, message = "主键不能小于1", groups = [Update::class])
    @field:NotNull(message = "不能为空", groups = [Update::class])
    var id: Long? = null,

    @Schema(title = "用户的登录名，必须唯一且不能为空")
    @field:Size(max = 32, message = "长度不能超过32")
    @field:NotBlank(message = "不能为空", groups = [Insert::class])
    var username: String? = null,

    @Schema(title = "用户密码的加密哈希值，存储加密后的密码而非明文")
    @field:Size(max = 255, message = "长度不能超过255")
    @field:NotBlank(message = "不能为空", groups = [Insert::class])
    @JsonIgnore
    var password: String? = null,

    @Schema(title = "用户的昵称，必须唯一且不能为空")
    @field:Size(max = 128, message = "长度不能超过128")
    @field:NotBlank(message = "不能为空", groups = [Insert::class])
    var nickname: String? = null,

    @Schema(title = "头像")
    @field:Size(max = 256, message = "长度不能超过256")
    var avatar: String? = null,

    @Schema(title = "最后一次修改昵称的时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var lastUpdateNicknameTime: LocalDateTime? = null,

    @Schema(title = "用户的手机号")
    @field:Size(max = 13, message = "长度不能超过13")
    var phone: String? = null,

    @Schema(title = "记录创建的时间戳")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var createTime: LocalDateTime? = null,

    @Schema(title = "用户最后一次登录的时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var lastLoginTime: LocalDateTime? = null,

    @Schema(title = "用户账户锁定结束时间，如果账户被锁定则为非空")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    var lockoutEndsTime: LocalDateTime? = null
)